// 导入axios 向服务器发送请求
import axios from 'axios'
// 配置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})

// 登录请求
export const loginApi = (params) => {
  return axios.post('login', params)
}
// 侧面导航请求
export const menusApi = (params) => {
  return axios.get('menus', params)
}
// 获取用户信息请求
export const getUsers = (params) => {
  return axios.get('users', { params })
}
// 修改用户状态,params 为get 请求携带的数据 为对象
export const status = (id, type) => {
  // return axios.put('users/' + id + '/state/' + type)
  return axios.put(`users/${id}/state/${type}`)
}
// 添加用户请求
export const addUser = (params) => {
  return axios.post('users', params)
}
// 编辑用户请求
export const editUser = (id, params) => {
  return axios.put(`users/${id}`, params)
}
// 删除用户请求
export const delUser = (id) => {
  return axios.delete(`users/${id}`)
}
